<?php

namespace app\index\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class MfwCheckOrder extends Command {

    protected function configure() {
        $this->setName('mfw_check_order')->setDescription('Here is the remark ');
    }

    protected function execute(Input $input, Output $output) {
        $i=1;
        while ($i>0) {
            //延迟 0.5秒
            usleep(500000);
            $this->task();
        }
    }
    public function task()
    {
        $mfw_order=Db::name('mfw_order')->where('ischeck',"<>",'1')->find();
        if($mfw_order){
            $m_order_check=new \app\common\model\OrderCheck();
            $new_order=$m_order_check->mfw_transform_order($mfw_order);
            $old_order=Db::name('order')->where('order_id',$mfw_order['order_id'])->find();
            if($old_order){
                $m_order_check->check($new_order,$old_order);
                $m_order_check->add_order_check();
                $m_order_check->add_exceptional_order();
                Db::name('mfw_order')->where('order_id',$mfw_order['order_id'])->update(array('ischeck'=>true));
            }else{
                Db::name("order")->insert($new_order);
            }

        }
    }

}
